package com.chey.controller;

import com.chey.domain.ResponseData;
import com.chey.domain.Updata;
import com.chey.service.ApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author JanYao
 * @version 0.1
 */
@RestController
public class ApplyController {

    @Autowired
    private ApplyService applyService;
    @PutMapping("/apply")
    public ResponseData apply(@RequestBody Updata updata){
        System.out.println("检查数据有效性："+updata);
        Integer apply = applyService.apply(updata);
        ResponseData data = new ResponseData();
        data.setCode(apply>0?200:500);
        return data;
    }

    @GetMapping("/view")
    public ResponseData apply(){
        ResponseData data = new ResponseData();
        data.setCode(200);
        List<Updata> query = applyService.query();
        data.setData(query);
        System.out.println(data);
        return data;
    }
}
